﻿using System;
using System.Globalization;
using System.Xml;
using System.Xml.Serialization;

namespace openSourceC.DaylifeClient
{
	/// <summary>
	///		Summary description for Image.
	/// </summary>
	[Serializable]
	[XmlType("image")]
	public class Image
	{
		/// <summary></summary>
		[XmlElement("caption")]
		public string Caption { get; set; }

		/// <summary></summary>
		[XmlElement("daylife_url")]
		public string DaylifeUrl { get; set; }

		/// <summary></summary>
		[XmlElement("height")]
		public int? Height { get; set; }

		/// <summary></summary>
		[XmlElement("image_id")]
		public string ImageId { get; set; }

		/// <summary></summary>
		[XmlElement("image_story_relevance")]
		public int? ImageStoryRelevance { get; set; }

		/// <summary></summary>
		[XmlElement("image_topic_relevance")]
		public int? ImageTopicRelevance { get; set; }

		/// <summary></summary>
		[XmlElement("source")]
		public Source Source { get; set; }

		/// <summary></summary>
		[XmlElement("thumb_url")]
		public string ThumbUrl { get; set; }

		/// <summary>Gets or sets the time stamp of the image expressed as a <see cref="DateTimeOffset"/>.</summary>
		[XmlIgnore]
		public DateTimeOffset? TimestampValue { get; set; }

		/// <summary>Gets or sets the time stamp of the image expressed in UTC.</summary>
		[XmlElement("timestamp")]
		public string Timestamp
		{
			get { return TimestampValue.HasValue ? TimestampValue.Value.ToString(DaylifeExtensions.TimestampFormat) : null; }

			set
			{
				if (string.IsNullOrEmpty(value))
				{
					TimestampValue = null;
				}
				else
				{
					TimestampValue = DateTimeOffset.ParseExact(value, DaylifeExtensions.TimestampFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal);
				}
			}
		}

		/// <summary>Gets or sets the time stamp epoch (UNIX time) expressed in UTC.</summary>
		[XmlElement("timestamp_epoch")]
		public int? TimestampEpochValue { get; set; }

		/// <summary>Gets or sets the Url of the image.</summary>
		[XmlElement("url")]
		public string Url { get; set; }

		/// <summary></summary>
		[XmlElement("width")]
		public int? Width { get; set; }


		/// <summary>Gets or sets the array of all the out-of-band elements.</summary>
		[XmlAnyElement]
		public XmlElement[] ZElements { get; set; }
	}
}
